#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sqlcontroller.h"
#include "maincontroller.h"
#include <QTableWidgetItem>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle(tr("主界面"));

    //
    ui->tableWidget_user->setColumnCount(3);
    QStringList horizontalList;
    horizontalList << "ID" << "姓名" << "权限";
    ui->tableWidget_user->setHorizontalHeaderLabels(horizontalList);
    QList<UserInfo> uInfo = SqlController::getInstance()->getAllUserInfo();
    ui->tableWidget_user->setRowCount(uInfo.size());
    for (int i=0; i<uInfo.size(); i++)
    {
        QTableWidgetItem *idItem = new QTableWidgetItem(QString::number(uInfo[i].id));
        ui->tableWidget_user->setItem(i, 0, idItem);
        QTableWidgetItem *nameItem = new QTableWidgetItem(uInfo[i].name);
        ui->tableWidget_user->setItem(i, 1, nameItem);
        QTableWidgetItem *authItem = new QTableWidgetItem(QString::number(uInfo[i].auth));
        ui->tableWidget_user->setItem(i, 2, authItem);
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_btn_student_clicked()
{
    MainController::getInstance()->hideMainView();
    MainController::getInstance()->showStudentView();
}

